<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/28 0028
 * Time: 14:44
 */

namespace app\admin\controller;



use app\home\model\BfConfig;
use app\home\model\BfAttachments;


class Config extends BaseController
{

    public function initialize(){

    }
    
    public function index(){
        $method = $this -> request -> method();
        if($method === 'GET'){
            $list = BfConfig :: where(['type' => 1]) -> select();
            $this->assign('list',$list);
            $bannerid = json_decode($list[6]['value'],true);
            $att = BfAttachments :: whereIn('id',$bannerid) ->select();
            $this -> assign('att',$att);
            return $this->fetch();
        }else{
            $post = $this -> request ->post('data');
            $bfconfigo = new BfConfig;
            $re = $bfconfigo -> saveAll($post,true);
            if($re){
                $this -> result($re,200,'修改成功');
            }else{
                $this -> result($re,0,'修改失败');
            }
        }
    }
    
    public function setseo(){
        $method = $this -> request -> method();
        if($method === 'GET'){
            $list = BfConfig :: where(['type' => 2]) -> select();
            $this->assign('list',$list);
            return $this->fetch();
        }else{
            $post = $this -> request ->post('data');
            $bfconfigo = new BfConfig;
            $re = $bfconfigo -> saveAll($post,true);
            if($re){
                $this -> result($re,200,'修改成功');
            }else{
                $this -> result($re,0,'修改失败');
            }
        }
    }
    
    public function email(){
        if(!Request::instance()->post()){
            $data = $this->_Email->getOne(input('id'));
            $this->assign('data',$data);
            return $this->fetch();
        }else{
            $data = [
                'smtp'=>input('smtp'),
                'name'=>input('name'),
                'addresser'=>input('addresser'),
                'addressername'=>input('addressername'),
                'password'=>input('password'),
                'coding'=>input('coding'),
                'smtp_attestation'=>input('smtp_attestation'),
                'html'=>input('html'),
                'order_inform'=>input('order_inform'),
            ];
            $re = $this->_Email->up(['id'=>input('id')],$data);
            if($re){
                return json_echo_msg(200,'修改成功');
            }else{
                return json_echo_msg(500,'修改失败');
            }
        }
    }
    public function social(){
        if(!Request::instance()->post()){
            $data = $this->_Social->getOne(input('id'));
            $this->assign('data',$data);
            return $this->fetch();
        }else{
            $data = [
                'google'=>input('google'),
                'linkedin'=>input('linkedin'),
                'pinterest'=>input('pinterest'),
                'twitter'=>input('twitter'),
                'facebook'=>input('facebook'),
                'youtube'=>input('youtube'),

            ];
            $re = $this->_Social->up(['id'=>input('id')],$data);
            if($re){
                return json_echo_msg(200,'修改成功');
            }else{
                return json_echo_msg(500,'修改失败');
            }
        }
    }
    
    public function upload(){
        $result = $this -> _upload();
        $this -> result($result,200,'上传成功','json');
    }
}